package yz;

/**
 * [125. 验证回文串](https://leetcode-cn.com/problems/valid-palindrome/) （简单）
 *
 * @author Yz
 * @since 2022-09-09 16:24
 */
public class LeetCode125_ValidPalindrome {
    
    public boolean isPalindrome(String s) {
        int left = 0, right = s.length() - 1;
        while (left < right) {
            while (left < right && !Character.isLetterOrDigit(s.charAt(left))) {
                left++;
            }
            while (left < right && !Character.isLetterOrDigit(s.charAt(right))) {
                right--;
            }
            if (Character.toLowerCase(s.charAt(left)) != Character.toLowerCase(s.charAt(right))) {
                return false;
            }
            left++;
            right--;
        }
        return true;
    }
    
}
